#ifndef CONFIGFILE_HPP
#define	CONFIGFILE_HPP

#include <string>
#include <tinyxml.h>
#include <vector>
#include <iostream>

typedef struct {

    std::string id;
    
    bool serviceServer;
    
    bool cmdVelocity;
    bool cmdCommand;
    
    bool cmdLEDFront;
    bool cmdLEDBody;
    bool cmdLEDRing;
  
    bool cmdCamera;
    bool cmdIR;

    std::string port;
    std::string node;
} InfoEpuck;

class ConfigFile {
public:

    ConfigFile(std::string configFile) {

        this->xmlFile = new TiXmlDocument(configFile.c_str());
        if (!this->xmlFile->LoadFile()) {
            std::cout << "Cannot open file" << std::endl;
            exit(EXIT_FAILURE);
        }
    }

    void readConfigEpucks();

    virtual ~ConfigFile() {
        delete xmlFile;
    }

    int getQuantityCfg() {
        return infoNode.size();
    }

    void printInfoEpuck() {

        printf("----------------\n");

        for (int i = 0; i < infoNode.size(); i++) {
            std::cout << "id: " << infoNode[i].id << std::endl;
            std::cout << "ServiceServer: " <<infoNode[i].serviceServer << std::endl;
            std::cout << "Node: " << infoNode[i].node << std::endl;
            std::cout << "Velocity: " << infoNode[i].cmdVelocity << std::endl;
            std::cout << "IR: " << infoNode[i].cmdIR << std::endl;
            std::cout << "Camera: " << infoNode[i].cmdCamera << std::endl;
            std::cout << "LEDFront: " << infoNode[i].cmdLEDFront << std::endl;
            std::cout << "LEDBody: " << infoNode[i].cmdLEDBody << std::endl;
            std::cout << "LEDRing: " << infoNode[i].cmdLEDRing << std::endl;
            std::cout << "port: " << infoNode[i].port << std::endl;
            printf("----------------\n");
        }
    }
    
    void printInfoEpuck(InfoEpuck *info) {

        printf("----------------\n");

        std::cout << "id: " << info->id << std::endl;
        std::cout << "ServiceServer: " <<info->serviceServer << std::endl;
        std::cout << "Node: " << info->node << std::endl;
        std::cout << "Velocity: " << info->cmdVelocity << std::endl;
        std::cout << "IR: " << info->cmdIR << std::endl;
        std::cout << "Camera: " << info->cmdCamera << std::endl;
        std::cout << "LEDFront: " << info->cmdLEDFront << std::endl;
        std::cout << "LEDBody: " << info->cmdLEDBody << std::endl;
        std::cout << "LEDRing: " << info->cmdLEDRing << std::endl;
        std::cout << "port: " << info->port << std::endl;
        printf("----------------\n");
    }
    
    InfoEpuck* getInfoNode( ){
        
        InfoEpuck *info = new InfoEpuck[infoNode.size()];
        
        for (unsigned int i = 0; i < infoNode.size(); i++) 
            info[i] = infoNode[i];
    
        return info;
    }

    InfoEpuck getInfoNodeID(unsigned int id){
        if(id < infoNode.size() )
            return infoNode[id];
    }
    
private:
    InfoEpuck readInfoEpuck(TiXmlElement *info);
    
    std::vector<InfoEpuck> infoNode;
    TiXmlDocument *xmlFile;
};

#endif	/* CONFIGFILE_HPP */

